<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>订单列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<div class="container">

    <!--{if isset($custID) && $custID != ""}-->
    <div class="comm_crub">
        <span class="now_crub">会员订单列表</span>
        <button type="button" class="btn btn-primary" style="float: right;margin:4px 15px 0px 0px;" onclick="history.go(-1)">返回上一级</button>
    </div>
    <!--{/if}-->

    <div class="comm_content">

        <div class="search-box">
            <div style="position:relative">
                <form class="form-inline" id="search_form" onsubmit="return false;">
                    <table>
                        <tbody>
                        <tr>
                            <td>订单编号：<input type="text" class="form-control input-sm w120" name="bill_code" maxlength="20"></td>
                            <td>会 员 名：<input type="text" class="form-control input-sm w120" name="custID" maxlength="30" value="<!--{$custID|default:''}-->"></td>
                            <td>收 货 人：<input type="text" class="form-control input-sm w120" name="deliver_name" maxlength="20"></td>
                            <td>手机号码：<input type="text" class="form-control input-sm w120" name="deliver_mobile" maxlength="11"></td>
                            <td>支付状态：<select class="form-control input-sm" name="pay_status">
                                    <option value="all">请选择</option>
                                    <!--{foreach from=$global_array.pay_status item=pay_status_name key=pay_status}-->
                                    <option value="<!--{$pay_status}-->"><!--{$pay_status_name}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>订单状态：<select class="form-control input-sm" name="bill_status">
                                    <option value="all">请选择</option>
                                    <!--{foreach from=$global_array.backend_bill_status item=bill_status_name key=bill_status}-->
                                    <option value="<!--{$bill_status}-->"><!--{$bill_status_name}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </td>
                            <td>支付方式：<select class="form-control input-sm" name="pay_type">
                                    <option value="">请选择</option>
                                    <option value="1">货到付款</option>
                                    <option value="2">在线支付</option>
                                </select>
                            </td>

                            <td>
                                订单品牌：<select class="form-control input-sm" name="billPlatform">

                                    <option value="all">全部</option>
                                    <option value="1">自营</option>
                                    <option value="2">澳粒</option>
                                </select>
                            </td>
                            <td>订单渠道：<select class="form-control input-sm" name="billChannel">
                                    <option value="all">请选择</option>
                                    <!--{foreach from=$global_array.bill_channel item=bill_channel_name key=bill_channel}-->
                                    <option value="<!--{$bill_channel}-->"><!--{$bill_channel_name}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </td>
                            <td>订单类型：<select class="form-control input-sm" name="billType">
                                    <option value="all">请选择</option>
                                    <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                    <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </td>
                        </tr>
                        <tr>

                            <td>退货状态：<select class="form-control input-sm" name="withdraw_status">
                                    <option value="">请选择</option>
                                    <option value="0">未退货</option>
                                    <option value="1">部分退货</option>
                                    <option value="2">全部退货</option>
                                </select>
                            </td>
                            <td>索要发票：<select class="form-control input-sm" name="invoice">
                                    <option value="">请选择</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </td>
                            <td>是否开票：<select class="form-control input-sm" name="is_the_invoice">
                                    <option value="">请选择</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </td>
                            <td colspan="2">下单日期：<input class="form-control input-sm w100" id="startDate" name="startDate" value="" readonly="readonly"   type="text" />
                                ～
                                <input class="form-control input-sm w100" id="endDate" name="endDate" value="" readonly="readonly" type="text" " />
                                <button type="button" class="btn btn-default btn-sm" onclick="bill.timeClear1();">清 空</button>
                            </td>
                        </tr>
                        <tr>

                            <td>配送日期：<input class="form-control input-sm w85" id="send_date" name="send_date" value="" readonly="readonly" type="text" />
                                <button type="button" class="btn btn-default btn-sm" onclick="bill.timeClear2();">清 空</button>
                            </td>

                            <td>城　　市：<select class="form-control input-sm" name="deliver_cityid" id="deliver_cityid">
                                    <option value="">请选择</option>
                                    <!--{if isset($city_array)}-->
                                    <!--{foreach from=$city_array item=city}-->
                                    <option value="<!--{$city.id}-->"><!--{$city.name}--></option>
                                    <!--{/foreach}-->
                                    <!--{/if}-->
                                </select>
                            </td>
                            <td>配 送 站：<select class="form-control input-sm" name="distribution_id" id="distribution_id">
                                    <option value="">请选择</option>
                                </select>
                            </td>
                            <td>下 单 人：<input type="text" class="form-control input-sm w120" name="creator" maxlength="20"></td>
                            <td>商　　品：<input type="text" class="form-control input-sm w120" name="goods_name_str" maxlength="20"></td>
                        </tr>
                        <tr>
                            <td>现 金 卡：<input type="text" class="form-control input-sm w120" name="card_no" maxlength="20"></td>
                            <td>优 惠 券：<input type="text" class="form-control input-sm w120" name="coupon_no" maxlength="20"></td>
                            <td>
                                代付订单：<input type="text" class="form-control input-sm w120" style="width: 100px" name="paying_agent_str" maxlength="20">
                            </td>
                            <td colspan="2">
                                收货地址：<input type="text" class="form-control input-sm w120" style="width: 300px" id="deliver_address_str" name="deliver_address_str" maxlength="20">
                            </td>
                        </tr>

                        <!-- start JunHui.Li  2015-02-02 新增顺丰运单号查询-->
                        <tr>
                            <td>
                                顺丰运单号：<input type="text" class="form-control input-sm w120" style="width: 120px" id="external_bill_str" name="external_bill_str" maxlength="20">
                            </td>
                            <td>
                                <button type="button" class="btn btn-primary btn-sm" onclick="bill.search();">查 询</button>&nbsp;&nbsp;
                                <button type="button" class="btn btn-warning btn-sm" onclick="bill.clear();">重 置</button>&nbsp;&nbsp;
                            </td>
                        </tr>
                        <!--end JunHui.Li  2015-02-02 新增顺丰运单号查询-->

                        </tbody>
                    </table>
                </form>
            </div>
        </div>

        <table id="flex" style="display:none"></table>

    </div>

    

</div>
<div id="pop" style="display: none;">

    <form class="form-horizontal" id="ticketForm" onsubmit="return false;">

        <div class="form-group">
            <label for="invoice_number" class="col-sm-3 control-label"><span class="red">*</span> 发票号：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control w300" id="invoice_number" name="invoice_number" maxlength="100" />
                <input type="hidden" id="bill_no" name="bill_no" value="" />
            </div>
        </div>

    </form>

</div>

<div id="useCardDialog" style="display: none;">

    <input type="hidden" id="card_h_bill_no" value=""/>
    <input type="hidden" id="card_h_bill_code" value=""/>
    <input type="hidden" id="card_check_pwd" value=""/>
    <div class="form-group">
        <label class="col-sm-3 control-label"> 订单编号：</label>
        <div class="col-sm-9">
            <label id="card_bill_code" class="col-sm-3 control-label"></label>
        </div>
        <label class="col-sm-3 control-label"> 应收金额：</label>
        <div class="col-sm-9">
            <label id="card_bill_money" class="col-sm-3 control-label"></label>
        </div>
        <label class="col-sm-3 control-label"> 现金卡：</label>
        <div class="col-sm-9">
            <input type="text" class="form-control w150" style="display: inline-block;" id="card_card_pwd" placeholder="请输入卡密码" />
            <button type="button" class="btn btn-sm" id="btn_use_card"> 验证 </button>
        </div>
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <span id="card_message"></span>
        </div>
    </div>
</div>

<div id="feePaidDialog" style="display: none;">

    <input type="hidden" id="feePaid_hidd_bill_no" value=""/>
    <input type="hidden" id="feePaid_hidd_bill_code" value=""/>
    <input type="hidden" id="feePaid_hidd_deliver_feePaid" value=""/>

    <div class="form-group">
        <label class="col-sm-3 control-label"> 订单编号：</label>
        <div class="col-sm-9">
            <label id="feePaid_bill_code" class="col-sm-3 control-label"></label>
        </div>

        <label class="col-sm-3 control-label" style="margin-top: 8px;"> 修改运费：</label>
        <div class="col-sm-9">
            <input type="text" class="form-control w150" style="display: inline-block;" id="deliver_feePaid" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" />
        </div>
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <span id="feePaid_message"></span>
        </div>
    </div>
</div>

<script type="text/javascript">

var table_id = <!--{$table_id}-->;

var fixed_json = <!--{$fixed_json}-->;

$("#flex").flexigrid({
    url:"/invokingAjax-backend/bill/billSearch.ajax?operFlg=1",
    dataType: "json",
    colModel : fixed_json,
    <!--{if $edit_permission}-->
    buttons : [
        {name: "添加订单", bclass: "add", onpress : "bill.add"}
    ],
    <!--{/if}-->
    sortname: "bill_no",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    autoload: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    },

    //拉伸宽度后触发
    onColResize:function(){

        var last_cid = arguments[0];
        var width = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=1',
            data:{
                table_id:table_id,
                last_cid:last_cid,
                width:width
            },
            call:function( o ){ }

        });

    },

    //隐藏后触发
    onToggleCol:function(){

        var cid = arguments[0];
        var hide = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=3',
            data:{
                table_id:table_id,
                cid:cid,
                hide:hide
            },
            call:function( o ){ }

        });

    },

    //拖拽后触发
    onDragCol:function(){

        var cid = arguments[0];
        var last_cid = arguments[1];

        E.ajax_get({
            url:'/invokingAjax-backend/system/flexigrid.ajax?operFlg=2',
            data:{
                table_id:table_id,
                cid:cid,
                last_cid:last_cid
            },
            call:function( o ){ }

        });

    }

});


/**
 * 订单操作类
 */
    var bill = {

        search: function() {

            if($('#deliver_address_str').val().length < 4 && $('#deliver_address_str').val().length >0)
            {
                alert('地址条件必须满4个字符');
                $('#deliver_address_str').select();
                $('#deliver_address_str').focus();
                return;
            }
            var dt = $("#search_form").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        clear: function() {
            document.getElementById('search_form').reset();
            this.search();
        },

        timeClear1: function() {
            $('#startDate').val('');
            $('#endDate').val('');
        },
        timeClear2: function() {
            $('#send_date').val('');
        },

        audit: function( bill_no ,remark) {
            this.bill_no = bill_no;
				if( remark.indexOf("%E5%88%87") >= 0  || //切
					remark.indexOf("%E9%85%8D%E4%BB%B6") >= 0 ||        //配件
					remark.indexOf("%E9%A4%90%E5%85%B7") >= 0 ||        //餐具
					remark.indexOf("%E8%9C%A1%E7%83%9B") >= 0 ||        //蜡烛
					remark.indexOf("%E5%8F%91%E7%A5%A8") >= 0 ||        //发票
					remark.indexOf("%E7%94%9F%E6%97%A5%E7%89%8C") >= 0 ||       //生日牌
					remark.indexOf("%E5%B7%A7%E5%85%8B%E5%8A%9B%E7%89%8C") >= 0         //巧克力牌
					){
	
				    E.confirm("订单备注内包含关于<span style='color:red'>切分、生日牌、蜡烛、餐具、发票</span>等信息请先与用户沟通再审核订单","bill.confirmAudit");
				 
				}else{
		
					E.confirm("您确认审核该订单吗？", "bill.confirmAudit");
				}            
            
        },


        confirmAudit: function() {
            E.ajax_get({
                url: "/invokingAjax-backend/bill/bill.ajax?operFlg=3",
                data: {
                    bill_no: this.bill_no
                },
                call: "bill.result"
            });
        },

        result: function( o ) {
            if (o.code == 200) {
                E.alert(o.message, 2);
                bill.search();
            } else {
                E.alert(o.message);
            }
        },

        add: function() {
            self.location = '/quanliadmin/app/callcenter/callcenter.pscript?operFlg=1&sign=1';
        },

        alter: function(bill_no) {
            window.open('/quanliadmin/app/bill/billEdit.pscript?operFlg=1&bill_no=' + bill_no);
        },

        //澳粒订单修改
        AL_alter: function(bill_no) {
            window.open('/quanliadmin/app/bill/billEdit.pscript?operFlg=5&bill_no=' + bill_no);
        },


        cancel: function( bill_no ) {
            this.bill_no = bill_no;
            E.confirm("您确认取消该订单吗？", "bill.confirmCancel");
        },

        confirmCancel: function() {
            E.ajax_get({
                url: "/invokingAjax-backend/bill/bill.ajax?operFlg=4",
                data: {
                    bill_no: this.bill_no
                },
                call: "bill.result"
            });
        },

        //退货
        returnGoods : function( bill_no ) {
            window.open("/quanliadmin/app/bill/billReturn.pscript?operFlg=2&bill_no=" + bill_no);
        },

        //开发票
        makeTicket: function( bill_no ){
            $('#bill_no').val(bill_no);
            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"pop",   		 //获取id为"pop"元素内的HTML
                title: "开发票",       //弹出层标题
                css: "width:800px;",     //设置弹出层样式
                btnName: "保存",         //执行“确定”操作的按钮名称
                btnCall:"bill.check();"  //点击确定后执行的方法
            });
        },
        //验证发票
        check: function(){

            this.dt = E.getFormValues("ticketForm");
            var invoice_number = $.trim( $("#invoice_number").val() );
            var err_msg = '';

            if(invoice_number == ''){
                err_msg += '发票号不能为空，请填写<br />';
            }

            if(err_msg != ''){
                E.alert(err_msg);
            }else{
                bill.execute();
            }
        },

        //开票执行
        execute: function(){
            E.popup.close();
            E.loadding.open("正在保存，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/bill/billSearch.ajax?operFlg=100",
                data: this.dt,
                call: "bill.result"
            });
        },

        //返回结果
        result:function(o){
            if (o.code == 200) {
                E.alert(o.message, 2, "bill.load");
            } else {
                E.alert(o.message);
            }
            E.loadding.close();
        },

        load: function() {
            $("#flex").flexReload();
        },

        //下车，出仓状态验证现金卡
        showUseCardDialog: function(bill_no,bill_code,bill_receivable_money){

            $("#card_message").html("");
            $("#card_h_bill_no").val(bill_no);
            $("#card_h_bill_code").val(bill_code);
            $("#card_bill_code").text(bill_code);
            $("#card_bill_money").text(bill_receivable_money);
            $("#card_check_pwd").val("");
            $("#card_card_pwd").removeAttr("disabled");
            $("#btn_use_card").removeAttr("disabled");


            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"useCardDialog",   		 //获取id为"useCardDialog"元素内的HTML
                title: "验证现金卡",       //弹出层标题
                css: "width:600px;",     //设置弹出层样式
                btnName: "提交",         //执行“确定”操作的按钮名称
                btnCall:"bill.useCard();"  //点击确定后执行的方法
            });

            $("#card_card_pwd").val('');
            $("#btn_use_card").click(function(){
                $("#card_check_pwd").val("");
                var card_pwd = $("#card_card_pwd").val();
                bill.checkCard(card_pwd);
            });
        },

        checkCard: function(card_pwd){ //验证现金卡

            if (E.empty(card_pwd)) {
                E.alert('请输入现金卡密码');
                return false;
            }

            E.loadding.open('正在验证现金卡...');
            var bill_no = $("#card_h_bill_no").val();
            E.ajax_post({
                url: '/invokingAjax-backend/bill/bill.ajax?operFlg=6',
                data: {
                    card_pwd:card_pwd,
                    bill_no: bill_no
                },
                call: "bill.checkCardResult(o);"
            });


        },
        checkCardResult:function(o)
        {
            E.loadding.close();
            if(o.code==200)
            {
                var card_pwd = $("#card_card_pwd").val();
                $("#card_card_pwd").attr("disabled","disabled");
                $("#btn_use_card").attr("disabled","disabled");
                $("#card_check_pwd").val(card_pwd);

                $("#card_message").html("<span class='red' style='font-size: 16px;font-weight: bold;'>验证成功!卡号:"+ o.data[0].card_no+",面值:"+o.data[0].face_value+"</span>");
            }
            else
            {
                $("#card_check_pwd").val("");
                $("#card_message").html(o.message);
            }

            //alert(o.message);
        },

        //使用现金卡
        useCard:function()
        {
            var bill_no = $("#card_h_bill_no").val();
            var card_pwd = $("#card_check_pwd").val();

            if (E.empty(card_pwd)) {
                E.alert('现金卡验证不通过,请先验证现金卡!');
                return false;
            }
            E.loadding.open('正在提交现金卡...');
            E.ajax_post({
                url: '/invokingAjax-backend/bill/bill.ajax?operFlg=7',
                data: {
                    card_pwd:card_pwd,
                    bill_no: bill_no
                },
                call: "bill.useCardResult(o);"
            });

        },

        useCardResult:function(o)
        {

            E.loadding.close();
            if(o.code==200)
            {
                E.popup.close();
                bill.load();
                E.alert("验证成功!", 2 ,"");

            }
            else
            {
                bill.load();
                $("#card_card_pwd").removeAttr("disabled");
                $("#btn_use_card").removeAttr("disabled");
                E.alert(o.message);
            }

        },

        //下车，出仓状态修改运费
        showFeePaidDialog: function(bill_no,bill_code,deliver_feePaid){

            $("#feePaid_message").html("");
            $("#feePaid_hidd_bill_no").val(bill_no);
            $("#feePaid_hidd_bill_code").val(bill_code);
            $("#feePaid_bill_code").text(bill_code);
            $("#feePaid_hidd_deliver_feePaid").val(deliver_feePaid);

            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"feePaidDialog",   		 //获取id为"feePaidDialog"元素内的HTML
                title: "修改运费",       //弹出层标题
                css: "width:600px;",     //设置弹出层样式
                btnName: "提交",         //执行“确定”操作的按钮名称
                btnCall:"bill.upfeePaid();"  //点击确定后执行的方法
            });

            $("#deliver_feePaid").val(deliver_feePaid);

        },
        //修改运费
        upfeePaid:function()
        {
            if($("#deliver_feePaid").val()==""){
                E.alert("请输入运费金额");
                $("#deliver_feePaid").focus();
                return;
            }else if($("#feePaid_hidd_deliver_feePaid").val()==$("#deliver_feePaid").val()){
                E.alert("请修改运费金额");
                $("#deliver_feePaid").focus();
                return;
            }else if( parseFloat($("#deliver_feePaid").val())< 0){
                E.alert("运费金额不能为负数");
                $("#deliver_feePaid").focus();
                return;
            }
            E.confirm("您确认修改此订单的运费吗？", "bill.confirmFeePaid");

        },
        confirmFeePaid:function(){
            var bill_no= $("#feePaid_hidd_bill_no").val();
            var deliver_feePaid=$("#deliver_feePaid").val();
            E.loadding.open('正在修改运费...');
            E.ajax_post({
                url: '/invokingAjax-backend/bill/bill.ajax?operFlg=8',
                data: {
                    deliver_feePaid:deliver_feePaid,
                    bill_no: bill_no
                },
                call: "bill.useFeePaidResult(o);"
            });
        },
        useFeePaidResult:function(o)
        {

            E.loadding.close();
            if(o.code==200)
            {
                E.popup.close();
                bill.load();
                E.alert("运费修改成功!", 2 ,"");

            }
            else
            {
                bill.load();
                E.alert(o.message);
            }

        },

        //下车
        debus:function(bill_no){

            this.bill_no = bill_no;

            E.confirm("您确认执行下车操作吗？", "bill.excuteDebus");

        },

        excuteDebus:function(){

            E.loadding.open('正在下车中，请稍后...');
            E.ajax_post({
                url: '/invokingAjax-backend/bill/bill.ajax?operFlg=9',
                data: {
                    bill_no: this.bill_no
                },
                call:function(o){
                    E.loadding.close();
                    if(o.code == 200){
                        bill.load();
                        E.alert(o.message, 2, '');
                    }else{
                        E.alert(o.message);
                    }
                }
            });
        }

    };

    $('#startDate').datepicker();
    $('#endDate').datepicker();
    $('#send_date').datepicker();

    $(function() {

        $('#deliver_cityid').change(function() {
            var deliver_cityid = $(this).val();
            if (deliver_cityid == '') {
                $('#distribution_id').html('<option value="">请选择</option>');
            } else {
                E.ajax_get({
                    url: '/invokingAjax-comm/bill/distribution.ajax?operFlg=2',
                    data: {
                        deliver_cityid: deliver_cityid,
                        no_act: 1
                    },
                    call: function( o ) {
                        $('#distribution_id').html('<option value="">请选择</option>');
                        if (o.data) {
                            $.each(o.data, function(k, v) {
                                $('#distribution_id').append('<option value="' + v.distribution_id + '">' + v.distribution_name + '</option>');
                            });
                        }
                    }
                });
            }
        });

    });

</script>

</body>
</html>